﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ArcMapUI;
using System.Windows.Forms;
namespace AgrinsaGeoDao
{
   public static class Conexion
    {
       
      private static IWorkspace ws;
      public static IWorkspace Ws
      {
          get { return ws; }
          set { ws = value; }
      }
      public static void getWorkSapce(IMxDocument doc)
      {
          try
          {
              ws = ((IDataset)doc.ActiveView.FocusMap.Layer[0]).Workspace;
              //MessageBox.Show(ws.PathName);
          }
          catch (Exception ex)
          {
              MessageBox.Show("Error intentando obtener Worksapce " + ex.Message, "Agrinsa", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }

      //public Dictionary<int, Dictionary<string, object>> FincasCargadas(DateTime fechaIni, DateTime fechaFin)
      //{


      //    var dict = new Dictionary<int, Dictionary<string, object>>();
      //    //ICursor cur ;
      //    IFeatureCursor cur = null;
      //    try
      //    {

      //        IFeatureLayer capa = ArcMap.Document.SelectedLayer as IFeatureLayer;
      //        IQueryFilter _filter = new QueryFilterClass();


      //        _filter.WhereClause = "CREATE_DATE >= TO_DATE('" + fechaIni.Year.ToString() + "-" + fechaIni.Month.ToString() + "-" + fechaIni.Day.ToString() + "','YYYY-MM-DD') AND CREATE_DATE <= TO_DATE('" + fechaFin.Year.ToString() + "-" + fechaFin.Month.ToString() + "-" + fechaFin.Day.ToString() + "','YYYY-MM-DD')";
      //        _filter.SubFields = "*";
      //        if (capa != null)
      //        {

      //            //IFeatureSelection busqueda = capa as IFeatureSelection;
      //            //ISelectionSet selectionSet = busqueda.SelectionSet;

      //            cur = capa.Search(_filter, false);
      //            //selectionSet.Search(_filter, true, out cur);
      //            //IRow row;
      //            IFeature row;

      //            while ((row = cur.NextFeature()) != null)
      //            {
      //                dict.Add(row.OID, RowToDict(row));
      //            }
      //        }
      //        else
      //        {
      //            MessageBox.Show("Es Necesario Seleccionar  la Capa de Fincas", "Bioenergy", MessageBoxButton.OK, MessageBoxImage.Warning);
      //        }
      //    }
      //    catch (Exception ex)
      //    {
      //        MessageBox.Show(ex.Message);
      //        throw;
      //    }
      //    //finally
      //    //{
      //    //    if (cur != null)
      //    //        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cur);
      //    //}



      //    return dict;
      //}
    
    }
}
